<?php


error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

$colorVerdeRGB = '00FF00';
$colorRojoRGB = 'FF0000';

define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

date_default_timezone_set('America/Bogota');

require_once dirname(__FILE__) . '/../excelapiphp/PHPExcel/IOFactory.php';

if (!file_exists(dirname(__FILE__) ."/../templates/COMO_AM294_CHK_XXXXX_PeerReviewDIS.xls")) {
	exit("No hay plantillas con ese nombre " . EOL);
}

if (PHP_SAPI == 'cli')
	die('This example should only be run from a Web Browser');

$objPHPExcel = PHPExcel_IOFactory::load(dirname(__FILE__) ."/../templates/COMO_AM294_CHK_XXXXX_PeerReviewDIS.xls");


$objPHPExcel->setActiveSheetIndex(1)->setCellValue('C10', '12345');
$objPHPExcel->getActiveSheet()->getStyle('C14')->applyFromArray(
    array(
        'fill' => array(
            'type' => PHPExcel_Style_Fill::FILL_SOLID,
            'color' => array('rgb' => $colorVerdeRGB)
        )
    )
);

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objPHPExcel->setActiveSheetIndex(0);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing->setPath(dirname(__FILE__) .'/../imagenes/logoaccenture.png');
$objDrawing->setCoordinates('G3');
$objDrawing->setOffsetX(-8);
$objDrawing->setOffsetY(-7);

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objPHPExcel->setActiveSheetIndex(2);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing->setPath(dirname(__FILE__) .'/../imagenes/logoaccenture.png');
$objDrawing->setCoordinates('F2');
$objDrawing->setOffsetX(210);
$objDrawing->setOffsetY(5);

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objPHPExcel->setActiveSheetIndex(3);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing->setPath(dirname(__FILE__) .'/../imagenes/logoaccenture.png');
$objDrawing->setCoordinates('F3');
$objDrawing->setOffsetX(70);
$objDrawing->setOffsetY(0);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

$objWriter->save('COMO_AM294_CHK_12345_PeerReviewDIS.xls');
$file='COMO_AM294_CHK_12345_PeerReviewDIS.xls';
// Redirect output to a client’s web browser (Excel5)
if (file_exists($file)){
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename='.basename($file));
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit("Se guardo el archivo" . EOL);
}else{
	exit("No se guardo el archivo" . EOL);
}


